import { createDefineMock } from "vite-plugin-mock-dev-server";
import path from "path";
const defineMock = createDefineMock((mock) => {
  mock.url = path.join(import.meta.env.VITE_APP_BASE_API, mock.url);
});

const list = [
  {
    createBy: "admin",
    createTime: "2023-04-23 16:11:40",
    updateBy: null,
    updateTime: null,
    remark: "",
    postId: 1,
    postCode: "ceo",
    postName: "董事长",
    postSort: 1,
    status: "0",
    flag: false,
  },
  {
    createBy: "admin",
    createTime: "2023-04-23 16:11:40",
    updateBy: null,
    updateTime: null,
    remark: "",
    postId: 2,
    postCode: "se",
    postName: "项目经理",
    postSort: 2,
    status: "0",
    flag: false,
  },
  {
    createBy: "admin",
    createTime: "2023-04-23 16:11:40",
    updateBy: null,
    updateTime: null,
    remark: "",
    postId: 3,
    postCode: "hr",
    postName: "人力资源",
    postSort: 3,
    status: "0",
    flag: false,
  },
  {
    createBy: "admin",
    createTime: "2023-04-23 16:11:41",
    updateBy: null,
    updateTime: null,
    remark: "",
    postId: 4,
    postCode: "user",
    postName: "普通员工",
    postSort: 4,
    status: "0",
    flag: false,
  },
];
export default defineMock([
  {
    url: "/api/system/post/list",
    method: ["GET"],
    body: {
      code: 200,
      data: {
        list: list,
        total: list.length,
      },
      msg: "success",
    },
  },
  {
    url: "/api/system/post/del",
    method: ["DELETE"],
    body: {
      code: 200,
      msg: "删除成功",
    },
  },
  {
    url: "/api/system/post/add",
    method: ["POST"],
    body: () => {
      return {
        code: 200,
        msg: "添加成功",
      };
    },
  },
  {
    url: "/api/system/post/update",
    method: "put",
    body: {
      code: 200,
      msg: "修改成",
    },
  },
  {
    url: "/api/system/post/detail/:id",
    method: ["GET"],
    body: ({ params }) => {
      console.log("res", params);
      // const id = parseInt(url.slice(url.lastIndexOf("/") + 1));

      const info = list.find((item) => item.postId == params.id);

      return {
        code: 200,
        data: info,
        msg: "success",
      };
    },
  },
]);
